package tcp.heartbeat;

import java.util.List;
import java.util.concurrent.*;

import tcp.Watcher;

public class HeartBeatManager {
	private List listOfFileStoreNodes = null ;
	//Number of seconds, will be mutliplied by 1000 miliseconds later
	public static final int HEARTBEAT_CHECK_PERIOD = 10;
	public static final int NUMBER_OF_HEARTBEAT_THREADS = 4;
	public static final int HEARTBEAT_PORT = 6565 ;
	private Watcher itemWatcher;
	
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(NUMBER_OF_HEARTBEAT_THREADS);
	
	public HeartBeatManager(Watcher watcher,HeartbeatLostHandler handler){
		scheduler.scheduleAtFixedRate(new HeartbeatHandler(this,handler), 10, HEARTBEAT_CHECK_PERIOD, TimeUnit.SECONDS);
		this.itemWatcher = watcher;
	}
	public List getWatchedFileStores(String type){
		return this.itemWatcher.getListOfWatchedElements(type);
	}
	public void removeUnresponseFileStoreNode(String id){
		this.itemWatcher.removeWatchedElement(id) ;
	}
}
